package com.ityueqiangu.project.gallerycomment.service.impl;

import com.ityueqiangu.core.enums.SysFlagStatusEnum;
import com.ityueqiangu.core.util.ServletUtils;
import com.ityueqiangu.core.util.UserUtil;
import com.ityueqiangu.project.exhibitionInfo.domain.ExhibitionInfo;
import com.ityueqiangu.project.exhibitionInfo.service.IExhibitionInfoService;
import com.ityueqiangu.project.galleryappoint.service.IGalleryAppointService;
import com.ityueqiangu.project.gallerycomment.domain.ExhibitionComment;
import com.ityueqiangu.project.gallerycomment.mapper.ExhibitionCommentMapper;
import com.ityueqiangu.project.gallerycomment.service.IExhibitionCommentService;
import com.ityueqiangu.core.util.StringUtils;
import com.ityueqiangu.core.enums.CommonEnum;
import com.ityueqiangu.core.web.result.ResultDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author Clever、xia
 * @title: ExhibitionCommentServiceImpl
 * @description:
 * @date 2021-03-18 17:36:49
 */
@Service
public class ExhibitionCommentServiceImpl implements IExhibitionCommentService{

    @Autowired
    private ExhibitionCommentMapper exhibitionCommentMapper;
    @Autowired
    private IExhibitionInfoService exhibitionInfoService;

    /**
     * 查询分页记录
     *
     * @return 返回集合，没有返回空List
     */
     public List<ExhibitionComment> selectExhibitionCommentList(ExhibitionComment exhibitionComment) {
       return exhibitionCommentMapper.selectExhibitionCommentList(exhibitionComment);
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回ResultInfo
     */
    public ExhibitionComment selectExhibitionCommentById(Integer id) {
    	return exhibitionCommentMapper.selectExhibitionCommentById(id);
    }
	
    /**
     * 新增
     *
     * @param exhibitionComment 新增的记录
     * @return 返回ResultInfo
     */
    public Integer insertExhibitionComment(ExhibitionComment exhibitionComment) {
        ExhibitionInfo exhibitionInfo = exhibitionInfoService.selectExhibitionInfoById(exhibitionComment.getExhibitionId());
        exhibitionComment.setGalleryId(exhibitionInfo.getGalleryId());
        exhibitionComment.setGalleryName(exhibitionInfo.getGalleryName());
        exhibitionComment.setExhibitionId(exhibitionInfo.getId());
        exhibitionComment.setExhibitionName(exhibitionInfo.getExhibitionName());
        exhibitionComment.setCommentUserId(UserUtil.getCurrentUser(ServletUtils.getRequest()).getId());
        exhibitionComment.setCommentUserName(UserUtil.getCurrentUser(ServletUtils.getRequest()).getLoginName());
        return exhibitionCommentMapper.insertExhibitionComment(exhibitionComment);
    }
	
	
    /**
     * 修改
     *
     * @param exhibitionComment 修改的记录
     * @return 返回
     */
    public Integer updateExhibitionComment(ExhibitionComment exhibitionComment) {
    	return exhibitionCommentMapper.updateExhibitionComment(exhibitionComment);
    }
	
  
    /**
     * 删除记录
     *
     * @param id 主键
     * @return 返回
     */
    public Integer deleteExhibitionCommentById(Integer id) {
    	return exhibitionCommentMapper.deleteExhibitionCommentById(id);
    }

    @Override
    public Integer replay(ExhibitionComment exhibitionComment) {
        ExhibitionInfo exhibitionInfo = exhibitionInfoService.selectExhibitionInfoById(exhibitionComment.getExhibitionId());
        exhibitionComment.setReplyUserId(UserUtil.getCurrentUser(ServletUtils.getRequest()).getId());
        exhibitionComment.setReplyUserName(UserUtil.getCurrentUser(ServletUtils.getRequest()).getLoginName());
        exhibitionComment.setIsReply(SysFlagStatusEnum.ONE.getKey());
        exhibitionComment.setGalleryId(exhibitionInfo.getGalleryId());
        exhibitionComment.setGalleryName(exhibitionInfo.getGalleryName());
        exhibitionComment.setExhibitionId(exhibitionInfo.getId());
        exhibitionComment.setExhibitionName(exhibitionInfo.getExhibitionName());
      return   exhibitionCommentMapper.updateExhibitionComment(exhibitionComment);
    }

}